<template>
  <div id="app">
    <!-- 加载中效果 -->
    <div class="loading" v-if="loading">
      <img src="@/assets/loading.gif" alt="加载中..." />
    </div>
    <transition :name="transitionName">
      <router-view class="page"></router-view>
    </transition>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  created() {
    const map = JSON.parse(localStorage.getItem("numList")) || {};
    this.$store.commit("setNumList", map);
  },
  computed: {
    ...mapState(["loading"]),
  },
  data() {
    return {
      transitionName: "",
    };
  },
  watch: {
    //根据路由进入的页面使用vant样式动画来进行对应的动画
    $route(to, from) {
      if (to.name === "Search" && from.name === "GoodsList") {
        this.transitionName = "van-slide-right";
      } else if (to.name === "GoodsPron" && from.name === "GoodsList") {
        this.transitionName = "van-slide-up";
      } else if (to.name === "Cart" && from.name === "Search") {
        this.transitionName = "van-slide-left";
      }
    },
  },
};
</script>

<style lang="scss" scoped>
@import "./css/globel.scss";
.page {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  background-color: #fff;
}
.loading {
  @include fixed(0, 0, 999);
  width: 100%;
  height: 100vh;
  background-color: rgba(255, 255, 255, 0.5);
  img {
    width: 500px;
    height: 500px;
    @include center(absolute);
  }
}
</style>
